#!/bin/bash

# 文件名
FILE="/etc/chrony/chrony.conf"
# 备份文件
BACKUP_FILE="${FILE}.bak"

# 创建备份
sudo cp "$FILE" "$BACKUP_FILE"

# 要注释的行号和新增的内容
START_LINE=17    # 从第几行开始注释
END_LINE=20      # 到第几行结束注释
NEW_LINES=(
    "server ntp.aliyun.com iburst"
    "server ntp2.aliyun.com iburst"
    "server ntp3.aliyun.com iburst"
    "server ntp4.aliyun.com iburst"
    "server ntp5.aliyun.com iburst"
    "server ntp6.aliyun.com iburst"
    "server ntp7.aliyun.com iburst"
    "server time.neu.edu.cn iburst"
    "server 139.199.214.202 iburst"
)

# 注释指定范围的行
sudo sed -i "${START_LINE},${END_LINE}s/^/# /" "$FILE"

# 在文件末尾增加新行
for line in "${NEW_LINES[@]}"; do
    echo "$line" | sudo tee -a "$FILE" > /dev/null
done

echo "ntp修改脚本执行完成"